package tests;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import org.junit.Test;

import code.Action;
import code.ActionFinishedException;

public abstract class ActionTest {
	protected abstract Action createAction();

	@Test
	public void testActionFinished() throws ActionFinishedException {
		Action action = createAction();
		while (!action.isFinished()) {
			try {
				action.doStep();
			} catch (ActionFinishedException e) {
				fail("action was not supposed to be finished, we just checked");
			}
		}
		assertTrue(action.isFinished());
		action.doStep();
	}

	@Test
	public void onlyOneStep() {
		try {
			Action action = createAction();

			assertTrue(action.isReady());
			assertFalse(action.isInProgress());
			assertFalse(action.isFinished());

			action.doStep();

			while (!action.isFinished()) {
				assertFalse(action.isReady());
				assertTrue(action.isInProgress());
				assertFalse(action.isFinished());
				action.doStep();
			}

			assertFalse(action.isReady());
			assertFalse(action.isInProgress());
			assertTrue(action.isFinished());

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
